﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.WebComponent
Imports Lsk.Business
Imports Lsk.Data
Imports FlickrNet
Partial Class ViewPhoto
    Inherits System.Web.UI.Page

    Private Shared prevPage As String = String.Empty

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then

            Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
            Dim PropertyDT As New Data.DataTable
            If Not Request.QueryString("id") Is Nothing Then ' Get PropertyId at AW_Picture
                lblPropertyID.Text = Request.QueryString("id").ToString()
            Else
                Response.Redirect("~/Default.aspx")
            End If
            Try
                prevPage = CType(Session.Item("Back"), String)


            Catch
                Response.Redirect("~/Default.aspx")
                Return
            End Try


            Try
                objDB.OpenConnection()

                LoadPhoto(objDB)
                'LoadUploadPhoto()
            Catch
                divError.Visible = True
                lblMsgError.Text = "Error getting data from Database."
                Return
            Finally
                If (objDB IsNot Nothing) Then
                    objDB.CloseConnection()
                End If
            End Try
        End If
    End Sub

    Private Sub LoadPhoto(ByVal objDB As Database)
        Dim PictureDT As New Data.DataTable
        'Getting Current Picture Information
        objDB.dbVariable.SQLString = "SELECT PictureId,Picture,pictureURL,PictureDesc, isThumbnail FROM AW_Picture WHERE PropertyId=@PropertyId"
        objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(lblPropertyID.Text))
        objDB.FillData(PictureDT, "Picture", Database.SQLCommandType.NormalString)
        objDB.ClearParameter()

        'Populating Images
        dlUploadedPhoto.DataSource = PictureDT
        dlUploadedPhoto.DataBind()

    End Sub

    Protected Sub dlUploadedPhoto_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlUploadedPhoto.ItemCommand

    End Sub

    Protected Sub btnDone_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDone.Click
        If String.IsNullOrEmpty(prevPage) Then
            Response.Redirect("~/DashBoard.aspx")
        Else
            Dim arr() As String = prevPage.Split("ڡ")
            Response.Redirect(arr(0).ToString)
        End If
    End Sub

    Protected Sub rblSelectedPicture_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim rbList As RadioButtonList = DirectCast(sender, RadioButtonList)
        If (rbList.SelectedIndex = 0) Then
            For nLoop As Integer = 0 To dlUploadedPhoto.Items.Count - 1
                Dim rbListControls As RadioButtonList = DirectCast((dlUploadedPhoto.Items(nLoop).FindControl("rblSelectedPicture")), RadioButtonList)
                If (rbList.ClientID <> rbListControls.ClientID) Then
                    rbListControls.SelectedIndex = 1
                End If
            Next
        End If


    End Sub
End Class
